package com.icbc.payfront.test;

import com.icbc.api.DefaultIcbcClient;
import com.icbc.api.IcbcApiException;
import com.icbc.api.IcbcConstants;
import com.icbc.api.internal.util.internal.util.fastjson.JSONObject;
import com.icbc.api.request.MybankPayDigitalwalletUnifiedorderRequestV1;
import com.icbc.api.response.MybankPayDigitalwalletUnifiedorderResponseV1;
import org.junit.Test;

import java.util.UUID;
/**
 * 数字货币统一下单
 */

public class MybankPayDigitalwalletUnifiedorderV1 {
    //网关公钥
    protected static final String APIGW_PUBLIC_KEY = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCwFgHD4kzEVPdOj03ctKM7KV+16bWZ5BMNgvEeuEQwfQYkRVwI9HFOGkwNTMn5hiJXHnlXYCX+zp5r6R52MY0O7BsTCLT7aHaxsANsvI9ABGx3OaTVlPB59M6GPbJh0uXvio0m1r/lTW3Z60RU6Q3oid/rNhP3CiNgg0W6O3AGqwIDAQAB";

    //网关私钥
    protected static final String MY_PRIVATE_KEY = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCf/XnuGrWxNJtObi2HgqZHknKqltPdbE6Lf0ebgSr2lVY89H33DeBQhyOXPCOaGS2DVeH+qdzD0KXEjQy59SBVOMNqpkVQcBBWmkQnATnaYCvAnHSwa1IZFH7UluV8pcmi6iBzLYZrq0Drz4ydrSFd4Ufc7jMDgWW2wPkzM64LTTKjBstavqkKUry2OcGxHgfJU+ITUDJ0de2d5gt86es/jaTsF6YTpji8iJTIjHtZgMAbOf6YOZ2yub074uZgsm7q7OPDTT5u0wHC0MgP5xR5MRhMPdWOiHC0sCi2jUReERZAuuNGYzpPdvGV+GeNlkJJiQXBdmfCQ7mAmWAQ7mCpAgMBAAECggEABR3mOGdCSFiWXvvHGP5kswVMBYitXfeIy41WjPKknR5Jk8l9/djDw8+Oo9eYi+UiP4EPqUVleh3CL3cTYR8l2ZPnLBIFRX1QCHUGmPjBEOrie1aFpN7J0WOGauYokMP8nuk+AHEES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q0MPIMP6eywck=";

    //appid
    protected static final String APP_ID = "10000000000000199058";

    @Test
    public void test_cop() throws IcbcApiException {
        DefaultIcbcClient client = new DefaultIcbcClient(APP_ID, IcbcConstants.SIGN_TYPE_RSA2, MY_PRIVATE_KEY, APIGW_PUBLIC_KEY);
        MybankPayDigitalwalletUnifiedorderRequestV1 request = new MybankPayDigitalwalletUnifiedorderRequestV1();
        MybankPayDigitalwalletUnifiedorderRequestV1.MybankPayDigitalwalletUnifiedorderRequestV1Biz bizContent = new MybankPayDigitalwalletUnifiedorderRequestV1.MybankPayDigitalwalletUnifiedorderRequestV1Biz();

        request.setServiceUrl("https://apipcs3.dccnet.com.cn/api/mybank/pay/digitalwallet/unifiedorder/V1");
        bizContent.setChantype(70); //true,交易来源
        bizContent.setInstructionId("ORDER000046");    //true,外围指令序号
        bizContent.setMerchantId("M00000049");   //true,商户编号
        bizContent.setSubMerchantId("S75913004");    //true,子商户编号
        bizContent.setAttach("");   //附加数据
        bizContent.setCommodity("商品描述");    //true,商品描述
        bizContent.setDetail("");   //商品详情
        bizContent.setBusstype("02044");   //true,业务种类编码
        bizContent.setBusscode("C202"); //true,业务类型编码
        bizContent.setOutTradeNo("ORDERDH000046");   //true,商户单号
        bizContent.setExpireMinutes(3600);  //订单失效时间间隔，默认5分钟
        bizContent.setTrandate("2021-03-31"); //true,交易日期
        bizContent.setTrantime("10:23:00"); //true,交易时间
        bizContent.setAmount("0");   //true,交易金额
        bizContent.setCurrtype("CNY"); //true,交易币种
        bizContent.setGoodsTag(""); //订单优惠标记
        bizContent.setTradeType("H5");    //true,交易类型(JSAPI -JSAPI支付 ;SCANPAY -扫码支付 ;APP -APP支付;H5-H5支付)
        bizContent.setNotifyUrl("http://81.69.7.141/postCallBack");    //true,通知地址
        bizContent.setOpenid("");   //用户标识(trade_type=JSAPI，此参数必传，用户在主商户appid下的 唯一标识。openid和sub_openid 可以选传其中之一，如果选择传 sub_openid,则必须传 sub_appid。)
        bizContent.setSubOpenid("");    //用户子标识( trade_type=JSAPI，此参数必传，用户在子商户appid下 的唯一标识。openid和 sub_openid可以选传其中之一，如 果选择传sub_openid,则必须传 sub_appid。)
        bizContent.setTermId("");   //终端号
        bizContent.setTermIp("");   //终端IP
        bizContent.setReceipt("Y");  //电子发票入口开放标识
        bizContent.setSceneInfo("");    //场景信息
        bizContent.setBak1(""); //备用字段
        bizContent.setBak2(""); //备用字段

        request.setBizContent(bizContent);

        System.out.println("上送报文");
        System.out.println(JSONObject.toJSONString(bizContent));

        String msgId = UUID.randomUUID().toString();
        MybankPayDigitalwalletUnifiedorderResponseV1 response = client.execute(request, msgId);
        if (response.isSuccess()) {
            // 业务成功处理
            System.out.println("返回报文");
            System.out.println(JSONObject.toJSONString(response));
        } else {
            //失败
            System.out.println("返回报文");
            System.out.println(JSONObject.toJSONString(response));
        }
    }
}
